<?php
/**
 * @param 传入的url地址
 * @url 腾讯的第三方接口地址
 * @sign 生成的签名
 * @$headers 请求头
 * @curlPost 请求参数
 */
index();
function index()
{
    $param = $_POST['imgUrl'];
    $url = 'https://recognition.image.myqcloud.com/face/detect';
    $sign = sign();
    curl($param, $url, $sign);
}
function curl($param = "", $url, $sign)
{
    $postUrl = $url;
    // 请求头
    $headers = array(
        'host:recognition.image.myqcloud.com',
        'authorization:' . $sign,
    );
    // 请求参数
    $curlPost = array(
        'appid' => '1257333357',
        'url' => $param,
    );
    $ch = curl_init(); //初始化curl
    curl_setopt($ch, CURLOPT_URL, $postUrl); //抓取指定网页
    curl_setopt($ch, CURLOPT_HEADER, 0); //设置header
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); //设置头信息
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //要求结果为字符串且输出到屏幕上
    curl_setopt($ch, CURLOPT_POST, 1); //post提交方式
    curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost); // 增加 HTTP Header（头）里的字段
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 终止从服务端进行验证
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    // curl_setopt($ch, CURLOPT_SSLCERT, EXTEND_PATH . '/apiclient_cert.pem'); //这个是证书的位置绝对路径
    // curl_setopt($ch, CURLOPT_SSLKEY, EXTEND_PATH . '/apiclient_key.pem'); //这个也是证书的位置绝对路径
    $data = curl_exec($ch); //运行curl
    curl_close($ch);
    echo $data;
}
// 签名
function sign()
{
    $appid = 1257333357;
    $secret_id = "AKIDGLErFOJxObYKr9f6lCPN9i3xhHeodY8V";
    $secret_key = "JRQDnALJ4cx62lHbicIn6C6mGXbS6Wgb";
    $expired = time() + 2592000;
    $onceExpired = 0;
    $current = time();
    $rdm = rand();
    $userid = "0";
    $fileid = "tencentyunSignTest";
    $srcStr = 'a=' . $appid . '&k=' . $secret_id . '&e=' . $expired . '&t=' . $current . '&r=' . $rdm;
    $signStr = base64_encode(hash_hmac('SHA1', $srcStr, $secret_key, true) . $srcStr);
    return $signStr;
}
